package com.example.project_dish;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button button;
    private EditText username;
    private EditText password;
    private LinearLayout linearLayout;
    private View drawable;
    @Override
    @SuppressWarnings("ResourceType")
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = findViewById(R.id.login);
        username = findViewById(R.id.username);
        password = findViewById(R.id.password);
        button.setOnClickListener(this);

        // 设置背景图片透明度
        linearLayout = findViewById(R.id.wda);
        method.setBackground(linearLayout,null);

        // 设置状态栏透明
        method.status_bar(this);
        if(this.getSupportActionBar() != null){
            this.getActionBar().hide();
        }
        // 设置EditText图标大小
        // name图标
        drawable = findViewById(R.drawable.name);

        Drawable drawable_name = this.getResources().getDrawable(R.drawable.name);
        drawable_name.setBounds(0,0,100,100);
        username.setCompoundDrawables(drawable_name,null,null,null);
        // password图标
        Drawable drawable_pw = getResources().getDrawable(R.drawable.pw);
        drawable_pw.setBounds(0,0,100,100);
        password.setCompoundDrawables(drawable_pw,null,null,null);
    }

    /*用于跳转到其他类的方法*/
    public static void launch(Activity activity){
        Intent intent = new Intent(activity, MainActivity.class);
        activity.startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        String username = this.username.getText().toString();
        String password = this.password.getText().toString();
        String ok = "登录成功";
        String fail = "登录失败";

        if (username.equals("yjy") && password.equals("123456")) {
            Toast.makeText(MainActivity.this, ok, Toast.LENGTH_LONG).show();
////            //跳转到点餐页面
            Intent intent = new Intent(MainActivity.this, OrderFoodActivity.class);
            startActivity(intent);
        }else {
            Toast.makeText(MainActivity.this, fail, Toast.LENGTH_LONG).show();
        }
    }
}